package com.cqjtu.education.service.impl;

import com.cqjtu.education.entity.Task;
import com.cqjtu.education.dao.TaskDao;
import com.cqjtu.education.service.TaskService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * (Task)表服务实现类
 *
 * @author makejava
 * @since 2022-04-20 15:50:56
 */
@Service("taskService")
public class TaskServiceImpl implements TaskService {
    @Resource
    private TaskDao taskDao;

    /**
     * 通过ID查询单条数据
     *
     * @param taskId 主键
     * @return 实例对象
     */
    @Override
    public Task queryById(String taskId) {
        return this.taskDao.queryById(taskId);
    }

    @Override
    public List<Task> queryAllByCourseId(String courseId) {
        return this.taskDao.queryAllByCourseId(courseId);
    }

    @Override
    public List<Task> queryExpiredByCourseId(String courseId) {
        return this.taskDao.queryExpiredByCourseId(courseId, new Date());
    }

    @Override
    public List<Task> queryNotExpiredByCourseId(String courseId) {
        return this.taskDao.queryNotExpiredByCourseId(courseId, new Date());
    }


    /**
     * 新增数据
     *
     * @param task 实例对象
     * @return 实例对象
     */
    @Override
    public Task insert(Task task) {
        task.setTaskId(UUID.randomUUID().toString());
        this.taskDao.insert(task);
        return task;
    }

    /**
     * 修改数据
     *
     * @param task 实例对象
     * @return 实例对象
     */
    @Override
    public Task update(Task task) {
        this.taskDao.update(task);
        return this.queryById(task.getTaskId());
    }

    /**
     * 通过主键删除数据
     *
     * @param taskId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String taskId) {
        return this.taskDao.deleteById(taskId) > 0;
    }
}
